package com.situ.springboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.springboot.entity.User;
import com.situ.springboot.mapper.UserMapper;
import com.situ.springboot.service.IUserService;
import com.situ.springboot.util.JSONResult;
import com.situ.springboot.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.util.List;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String name, String password) {
        return userMapper.login(name, password);
    }

    @Override
    public LayUITableResult selectByPage(Integer page, Integer limit) {
        // PageBean
        PageHelper.startPage(page, limit);
        List<User> list = userMapper.selectByPage();
        PageInfo pageInfo = new PageInfo(list);
        long total = pageInfo.getTotal();

        return LayUITableResult.ok(total, list);
    }

    @Override
    public JSONResult deleteById(Integer id) {
        userMapper.deleteById(id);
        return JSONResult.ok("删除成功");
    }

    @Override
    public JSONResult deleteByAll(Integer[] ids) {
        userMapper.deleteAll(ids);
        return JSONResult.ok("删除成功");
    }
}
